<? if ($c = stack('name')) {

$s = component_settings($c);
	
$now = parse_today();
$expires = date("Y-m-d", mktime(0,0,0, $now['m'], $now['d'] + (int)$s['new_user_expires'], $now['y']));;

$_record = array('kind' => TK_NEW_USER, 'expires' => $expires);

$_values	= array('firstname', 'lastname', 'middlename', 'gender', 'birthday', 'fact_index', 'fact_geo_id', 'fact_address', 'contactphone', 'contactphone2', 'idcode', 'category_id', 'socialstatus_id');

$_values_session = array('persontype_id', 'email', 'pass');

$check = $_POST; foreach($_values_session as $v) $check[$v] = gccUserInfo($v);
$check['persontype'] = $check['persontype_id'];
$check['id'] = gccUserInfo('person_id');


//debug($check, 'check');

$val = gccPersonStore($check);

//debug($val, 'val');


if ($val['stored']) {

	if ($vuser = datafetch('db_item', 'cs_person', "id= " . gccUserInfo('id'))) {

		if ($vuser['auth_id'] && $user = datafetch('db_item', tb('auth'), "id=$vuser[auth_id]")) {

			$user['time'] = date("H:i");

			$user['vuser'] = array_merge($vuser, gccLoadPerson($vuser['person_id']));	// load person data

			$user['settings'] = json_decode($user['settings'], true);
			if (!is_array($user['settings'])) $user['settings'] = array();

			create_session($user);
		}

	} else {

		$DATA['login_error'] = "Wrong login or password";
		// some diags for bad user/password
	}


	$res = array();
	foreach($_values as $v)
		$res[] = array($v, true, '');
	
	print(json_encode($res));
	exit;

} else {

	print($val['raw']);
	exit;
}

unstack();
}